<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="/classes/DBHelper.class.jsp"%>
<%@ include file="/classes/CommonHelper.class.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	pageContext.setAttribute("basePath", basePath);
%>
<%
	int curr = 1;
	if (!nullOrEmpty(getParameter(request, "curr"))) {
		try {
			curr = Integer.parseInt(getParameter(request, "curr"));
		} catch (Exception e) {
			curr = 1;
		}
	}
	List<Object> params = new ArrayList<Object>();
	String sql = " SELECT * FROM APP_QA t WHERE t.status = 'B' order by t.answer_time desc";
	List<Map<String, Object>> list = queryForListPage(sql, params, curr, 3);
	int total = queryForPageCount(sql, params);
	pageContext.setAttribute("curr", curr);
	pageContext.setAttribute("list", list);
	pageContext.setAttribute("total", total);
%>
<!DOCTYPE html>
<html>
<head>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>智能问答</title>
<link rel="stylesheet" href="css/jxw_css.css" />
<%-- <script type='text/javascript' src="${basePath }plugins/jquery/jquery-1.12.2.min.js"></script> --%>
<link rel="stylesheet" href="${basePath }plugins/layui/v1.0.9/css/layui.css" media="all">

</head>
<body>
	<iframe id="top" name="top" title="网站头部" width="100%" height="211" src="/snxf/toub/top.shtml" scrolling="no" frameborder="0" allowtransparency="true"></iframe>
	<div class="secmain w1000 ovhid">
		<div class="secleft l ">
			<div class="wdbox">
				<div class="wdlist">
					<ul>
						<c:forEach items="${list }" var="qa" varStatus="i">
							<c:if test="${i.index ne 0 }">
								<hr>
							</c:if>
							<li>
								<div class="wen">${qa.question }</div>
								<div class="da">${qa.answer }</div>
							</li>
						</c:forEach>
					</ul>
					<div id="demo7"></div>
					<form class="layui-form" action="" method="post" style="width: 800px;">
						<div class="lyinfo">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr class="layui-form-item">
									<td width="76" style="font-size: 18px; color: #2579B8; height: 40px;">我要提问</td>
									<td width="49">姓名：</td>
									<td width="112" class="layui-input-block">
										<input class="xm" type="text" name="question_name" lay-verify="required" autocomplete="off" placeholder="请输入您的姓名">
									</td>
									<td width="58">手机号：</td>
									<td width="105" class="layui-input-block">
										<input type="text" name="phone" lay-verify="phone" required autocomplete="off" placeholder="请输入手机号码" class="sjh">
									</td>
									<td width="57">验证码：</td>
									<td width="110" class="layui-input-block">
										<input type="text" name="vCode" lay-verify="required" autocomplete="off" placeholder="请输入验证码" class="yzm" style="display: inline-block;">
									</td>
									<td width="233">
										<img src="${basePath }common/img_code.jsp" style="height: 35px; width: 80px; cursor: pointer;" onclick="resetImg(this)" title="点我更换图片">
									</td>
								</tr>
							</table>
						</div>
						<div class="lysr">
							<textarea name="question" lay-verify="question" placeholder="请输入您的问题" class="layui-textarea" style="height: 80px; width: 630px;"></textarea>
							<div class="lybt">
								<button type="button" class="layui-btn" lay-submit="" style="margin-left: 220px;" lay-filter="submitBtn">立即提交</button>
								<button id="resetBtn" type="reset" class="layui-btn layui-btn-primary">重置</button>
							</div>


						</div>
					</form>
				</div>
			</div>
		</div>
		<jsp:include page="../zyfw/zyfw_right.jsp"></jsp:include>
		<jsp:include page="../zyfw/zyfw_bottom.jsp"></jsp:include>
		<script type='text/javascript' src="${basePath }plugins/jquery/jquery-1.12.2.min.js"></script>
		<script type="text/javascript" src="${basePath }plugins/layui/v1.0.9/layui.js"></script>
		<script charset="utf-8" src="${basePath }plugins/97date/4.8/WdatePicker.js"></script>
		<script type='text/javascript'>
			layui.use('form', function() {
				var $ = layui.jquery, form = layui.form();
				//自定义验证规则
				form.verify({
					question : function(value) {
						if (value.length < 5) {
							return '提问内容不能少于5个字符';
						}
						if (value.length > 2000) {
							return '提问内容不能超过2000个字符';
						}
					}
				});
				//监听提交
				form.on('submit(submitBtn)', function(data) {
					var index = layer.load(0, {
						shade : false
					});
					$.ajax({
						type : "POST",
						url : "${basePath }qa_sys/qa_save_do.jsp",
						data : data.field,
						dataType : 'json',
						cache : false,//不缓存数据
						success : function(data) {
							layer.close(index);
							if (data.status == '200') {
								parent.layer.alert(data.msg, {
									icon : 6
								});
								$("#resetBtn").click();
							} else {
								layer.alert(data.msg, {
									icon : 5
								})
							}
						},
						error : function(XMLHttpRequest, textStatus,
								errorThrown) {
							layer.close(index);
							layer.alert('连接错误', {
								icon : 5
							})
						}
					});
					return false;
				});
			});
			function resetImg(t) {
				$(t).attr("src",
						"${basePath }common/img_code.jsp?r=" + Math.random());
			}
			layui
					.use(
							[ 'laypage', 'layer' ],
							function() {
								var laypage = layui.laypage, layer = layui.layer;
								laypage({
									cont : 'demo7',
									curr : '${curr }',
									pages : Math.ceil('${total}' / 3),
									skip : true,
									jump : function(obj, first) {
										//得到了当前页，用于向服务端请求对应数据
										if (!first) {
											var index = layer.load(0, {
												shade : false
											});
											var curr = obj.curr;
											window.location.href = '${basePath}qa_sys/qa_save.jsp?curr='
													+ curr
													+ '&r='
													+ Math.random();
										}
									}
								});
							});
		</script>


</body>
</html>